using System;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class SkillManager : MonoSingleton<SkillManager>
{
    public SkillDataBase skillDataBase;
    public SkillData currentSkill;

    public void ReleaseSkill(SkillEnum skillEnum)
    {
        SkillData skillData = GetSkillData(skillEnum);
        skillData.owner = this.gameObject;
        currentSkill = skillData;
        GameObject skillPrefab = null;

        if (!string.IsNullOrEmpty(skillData.prefabName))
        {
            Vector3 creatPos = SkillTool.GetCharacterCenterPos(transform);
            skillPrefab = Instantiate(PathUtil.GetSkill(skillData.prefabName), creatPos, transform.rotation);
        }

        AddDeployerForSkill(skillData, skillPrefab);
    }

    /// <summary>
    /// 为技能添加技能部署器
    /// </summary>
    /// <param name="skillData"></param>
    /// <param name="skillPrefab"></param>
    private static void AddDeployerForSkill(SkillData skillData, GameObject skillPrefab)
    {
        SkillDeployer deployer = DeployerConfigFactory.AddSkillDeployer(skillData, skillPrefab) as SkillDeployer;
        deployer.skillData = skillData;
        deployer.InitDeployer();
    }

    /// <summary>
    /// 获取技能数据
    /// </summary>
    /// <param name="skillEnum"></param>
    /// <returns></returns>
    public SkillData GetSkillData(SkillEnum skillEnum)
    {
        SkillData skillData = skillDataBase.skills.Find(x => x.name == skillEnum.ToString());

        if(skillData != null )
            return skillData;

        return null;
    }
}
